<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户协议</title>
    <link rel="stylesheet" href="{__CSS__}/element_ui.css"/>
    <link rel="stylesheet" href="{__CSS__}/style.css"/>
    <script src="{__JS__}/vue2.js"></script>
    <script src="{__JS__}/element_ui.js"></script>
    <script src="{__JS__}/axios.min.js"></script>
    <script src="{__JS__}/request.js"></script>
</head>
<body>
{include file="/components/ueditor"}
<div id="app">
    <div class="app-loading" v-if="pageLoading">
        <div class="app-loading__logo">
            <img src="{__IMG__}/logo.png"/>
        </div>
        <div class="app-loading__loader"></div>
        <div class="app-loading__title">{$title}</div>
    </div>
    <el-card class="box-card" v-else>
        <div slot="header" class="clearfix">
            <span>用户协议</span>
        </div>
        <el-tabs v-model="activeName">
            <el-tab-pane label="用户协议" name="first">
                <ueditor @input="agreeOne" :value="formOne.content"></ueditor>
                <el-button type="primary" @click="save(1)" style="margin-top: 10px">立即保存</el-button>
            </el-tab-pane>
            <el-tab-pane label="隐私协议" name="second">
                <ueditor @input="agreeTwo" :value="formTwo.content"></ueditor>
                <el-button type="primary" @click="save(2)" style="margin-top: 10px">立即保存</el-button>
            </el-tab-pane>
        </el-tabs>
    </el-card>
</div>
<script>

    new Vue({
        el: '#app',
        data: function() {
            return {
                pageLoading: true,
                activeName: 'first',
                baseIndex: '/{:config("shop.backend_index")}/',
                formOne: {
                    type: 1,
                    content: ''
                },
                formTwo: {
                    type: 2,
                    content: ''
                }
            }
        },
        mounted() {
            this.pageLoading = false
            this.getBaseInfo()
        },
        methods: {
            async getBaseInfo() {
                let res = await request.get(this.baseIndex + 'system/agreement')
                this.formOne.content = res.data[1]
                this.formTwo.content = res.data[2]
            },
            agreeOne(content) {
                this.formOne.content = content
            },
            agreeTwo(content) {
                this.formTwo.content = content
            },
            async save(type) {
                let form = this.formOne
                if (type == 2) {
                    form = this.formTwo
                }

                let res = await request.post(this.baseIndex + 'system/agreement', form)
                if (res.code == 0) {
                    this.$message.success(res.msg)
                } else {
                    this.$message.error(res.msg)
                }
            }
        }
    })
</script>
</body>
</html>